package com.itcat.controller;


import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.PmsBrand;
import com.itcat.mysql.vo.PageResult;

import com.itcat.service.PmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService brandService;

    //添加品牌
    @PostMapping("create")
    public CommonResult<String> createBrand(@RequestBody PmsBrand pmsBrand){
        brandService.createBrand(pmsBrand);
        return CommonResult.success("ok");
    }

    //查询品牌
    @GetMapping("list")
    public CommonResult<PageResult> list(String keyword,
                                         @RequestParam(defaultValue = "1") Integer pageNum,
                                         @RequestParam(defaultValue = "10") Integer pageSize ){
        PageResult pageResult= brandService.list(pageNum,  pageSize,keyword);
        return CommonResult.success(pageResult);
    }

    //修改状态
    @PostMapping("update/showStatus")
    public CommonResult<String> showStatus( @RequestParam List<Long> ids,Long showStatus){
        brandService.showStatus(ids,showStatus);
        return CommonResult.success("ok");
    }
    //品牌制造商状态
    @PostMapping("update/factoryStatus")
    public CommonResult<String> updateFactory( @RequestParam List<Long> ids,Long factoryStatus){
        brandService.updateFactory(ids,factoryStatus);
        return CommonResult.success("ok");
    }

    //回显
    @GetMapping("/{id}")
    public CommonResult<PmsBrand> selectById(@PathVariable Long id){
        PmsBrand pmsBrand = brandService.selectById(id);
        return CommonResult.success(pmsBrand);
    }

    //修改
    @PostMapping("/update/{id}")
    public CommonResult<String> updateById( @PathVariable Long id, @RequestBody PmsBrand pmsBrand) {
        brandService.updateById(id,pmsBrand);
        return CommonResult.success("ok");
    }
    @GetMapping("delete/{id}")
    public CommonResult<String> deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return CommonResult.success("ok");
    }
}
